package org.smr.dev;

import java.util.List;

import org.smr.dev.matedata.EntityDef;
import org.smr.dev.matedata.FieldDef;

public class EntityDefCreater {

	/**
	 * 
	 * @param tableName
	 * @return
	 */
	public EntityDef create(String tableName){
		List<ColumnModel> columnModels = TableStructUtils.getTableStructure(tableName);
		return transformColumnModels2EntityDef(tableName, columnModels);
		
	}
	
	/**
	 * 鎶� ColumnModel 杞崲涓� EntityDef
	 * @param tableName
	 * @param columnModels
	 * @return
	 */
	public EntityDef transformColumnModels2EntityDef(String tableName, List<ColumnModel> columnModels){
		EntityDef javaBeanDef = new EntityDef();
		for(ColumnModel cm : columnModels){
			javaBeanDef.getFields().add(new FieldDef(cm.getFieldType(), cm.getFieldName(), ""));
		}
		javaBeanDef.setName(TableStructUtils.tableName2BeanName(tableName));
		return javaBeanDef;
	}
}
